package com.web.base.log.util;

import com.blue.jdbc.Page;
import com.web.base.log.message.AccusationRequest;
import com.web.base.log.message.AccusationResponse;
import com.web.base.log.model.Accusation;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 举报转换器
 * 
 * @author 代码由 blue-code 框架生成
 * @since 1.0 2018年06月20日
 */
public class AccusationConvertor
{
	private AccusationConvertor()
	{
	}
	
	public static Accusation toAccusation(AccusationRequest request)
	{
		if (request == null)
			return null;
		
		Accusation accusation = new Accusation();
		accusation.setId(request.getId());
		accusation.setUserId(request.getUserId());
		accusation.setTitle(request.getTitle());
		accusation.setContent(request.getContent());
		accusation.setCreateTime(request.getCreateTime());
		accusation.setState(request.getState());
		accusation.setExternalId(request.getExternalId());
		accusation.setExternalType(request.getExternalType());
		return accusation;
	}
	
	public static List<Accusation> toAccusation(List<AccusationRequest> requestList)
	{
		List<Accusation> list = new ArrayList<>();
		if (requestList == null || requestList.isEmpty())
			return list;
		
		for (AccusationRequest request : requestList)
		{
			list.add(toAccusation(request));
		}
		return list;
	}
	
	public static AccusationResponse toResponse(Accusation accusation)
	{
		if (accusation == null)
			return null;
		
		AccusationResponse response = new AccusationResponse();
		response.setId(accusation.getId());
		response.setUserId(accusation.getUserId());
		response.setTitle(accusation.getTitle());
		response.setContent(accusation.getContent());
		response.setCreateTime(accusation.getCreateTime());
		response.setState(accusation.getState());
		response.setExternalId(accusation.getExternalId());
		response.setExternalType(accusation.getExternalType());
		return response;
	}
	
	public static List<AccusationResponse> toResponse(List<Accusation> list)
	{
		List<AccusationResponse> responseList = new ArrayList<>();
		if (list == null || list.isEmpty())
			return responseList;
		
		for (Accusation accusation : list)
		{
			responseList.add(toResponse(accusation));
		}
		return responseList;
	}
	
	public static Map<Integer, AccusationResponse> toResponse(Map<Integer, Accusation> map)
	{
		Map<Integer, AccusationResponse> responseMap = new HashMap<>();
		if (map == null || map.isEmpty())
			return responseMap;
		
		for (Map.Entry<Integer, Accusation> entry : map.entrySet())
		{
			responseMap.put(entry.getKey(), toResponse(entry.getValue()));
		}
		return responseMap;
	}
	
	public static Page<AccusationResponse> toResponse(Page<Accusation> page)
	{
		if (page == null)
			return null;
		
		Page<AccusationResponse> responsePage = new Page<>();
		responsePage.setCurPage(page.getCurPage());
		responsePage.setRows(page.getRows());
		responsePage.setSize(page.getSize());
		responsePage.setStartRowNo(page.getStartRowNo());
		responsePage.setTotalPage(page.getTotalPage());
		responsePage.setObjectList(toResponse(page.getObjectList()));
		return responsePage;
	}
	
}
